#include <memory>
#include <thread>
#include <vector>
#include <atomic>
#include <mutex>
#include <unistd.h>
#include <iostream>

#include <iostream>

using namespace std;
#include <iostream>
#include <memory>
#include <thread>
using namespace std;
class A
{
private:
    int number;
public:
    A() { cout << "A()" << endl; }
    ~A() { cout << "~A()" << endl; }
    void funA()
    {
        cout << "A is good method!" << number << endl;
    }
};
void handler01(weak_ptr<A> q)
{
    //需要检测对象A是否存活
    std::this_thread::sleep_for(std::chrono::seconds(2));
    shared_ptr<A> ptmp = q.lock();
    if (ptmp != nullptr)
    {
        ptmp->funA();
    }
    else
    {
        cout << "A object is death" << endl;
    }

}
int main()
{
    {
        shared_ptr<A> p(new A());
        thread t1(handler01, weak_ptr<A>(p));
        t1.detach();
    }
    std::this_thread::sleep_for(std::chrono::seconds(10));
}

